package morning.cat.study.protostuff;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import morning.cat.study.Archive;

public class SerializableTest {

	 @Test
	    public void writeObject4() throws IOException {
	        User4 user = new User4();
	        user.setId(1004);
	        user.setName("晨猫");
	        user.setAddDate(Calendar.getInstance().getTime());
	        user.setNo("Xs01");
	        user.setArchive(new Archive("Mc001", "Hangzhou", "18366557620"));
	        System.out.println(user);

	        byte[] data = ProtostuffUtils.serialize(user);
	        FileUtils.writeByteArrayToFile(new File("User4.out"), data);
	    }

	    @Test
	    public void readObject4() throws IOException, ClassNotFoundException {
	        User4 user = ProtostuffUtils.deserialize(FileUtils.readFileToByteArray(new File("User4.out")), User4.class);
	        System.out.println(user);
	    }
}
